package cn.chenxiejia;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/***
 * @program: maven
 * @ClassName: File13
 * @Description: 目录的复制
 * @Author: chenxiejia
 * @Date: 2022/1/20 15:18
 * @version : V1.0
 */
public class File13 {
    public static void main(String[] args) throws IOException {
        //FileUtils.copyDirectory(new File("E:/aa"), new File("E:/aaa2"));
        copydir(new File("E:/aa"), new File("E:/aaa1"));
    }

    public static void copydir(File file, File tofile) throws IOException {
        if (!tofile.exists()) {
            tofile.mkdirs();
        }

        for (File t : file.listFiles()) {
            if (t.isDirectory()) {
                copydir(t, new File(tofile.getPath(), t.getName()));
            } else {
                Files.copy(t.toPath(), Paths.get(tofile.getPath() + "/" + t.getName()));
            }
        }


    }
}
